﻿namespace LeetCodeProject._0001_1000._001_100._41_50._049;

public class Solution
{
    public IList<IList<string>> GroupAnagrams(string[] strs)
    {
        var dic = new Dictionary<string, IList<string>>();
        IList<IList<string>> res = new List<IList<string>>();
        for (int i = 0; i < strs.Length; i++)
        {
            char[] a = strs[i].ToArray();
            Array.Sort(a);
            string str = String.Join("", a.Select(x => x.ToString()).ToArray());
            if (dic.ContainsKey(str))
                dic[str].Add(strs[i]);
            else
                dic[str] = new List<string> { strs[i] };
        }

        foreach (var item in dic.Keys)
        {
            res.Add(dic[item]);
        }

        return res;
    }
}